<template>
  <div>
    <h1>管理员的个人信息</h1>
    <el-descriptions class="margin-top" :column="1" border>
      <el-descriptions-item>
        <template slot="label"> 姓名 </template>
        {{ msg.name }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 所属学院 </template>
        {{ msg.collage }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 电话 </template>
        {{ msg.phone }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 邮箱 </template>
        {{ msg.email }}
      </el-descriptions-item>
    </el-descriptions>
    <div class="btn">
      <el-button @click="update">修改信息</el-button>
      <el-button @click="goback">返回</el-button>
    </div>
    <!-- 修改信息弹框 -->
    <el-dialog title="信息" :visible.sync="dialogVisible" width="30%">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="ture_updateInfo">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  created() {
    this.get_info();
  },
  data() {
    return {
      form: {},
      rules: {
        phone: { min: 11, max: 11, message: "电话长度为11位", trigger: "blur" },
        email: {
          type: "email",
          message: "请输入正确邮箱",
          trigger: ["blur", "change"],
        },
      },
      dialogVisible: false,
      msg: {},
    };
  },

  methods: {
    get_info() {
      this.$http
        .get("http://127.0.0.1:8080/minAdmin/get_minadminInfo")
        .then((res) => {
          this.msg = res.data.data[0];
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
    update() {
      this.dialogVisible = true;
    },

    // 确认修改信息
    ture_updateInfo() {
      this.dialogVisible = false;
      this.$http
        .post(
          "http://127.0.0.1:8080/minAdmin/update_minAdminInfo",
          this.$qs.stringify(this.form)
        )
        .then((res) => {
          if (res.data.status == 0) {
            this.$message.success(res.data.message);
            this.form = {};
            this.get_info();
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
    // 返回上一级
    goback() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang="less" scoped>
.btn {
  float: right;
  margin: 20px 0;
}
</style>
